class Unit:
	allUnits = []

	#name : String
	#mineral: int
	#gas: int
	#supply: int
	#time: int
	#builtBy: Unit
	#reqs: Unit[]
	#killsBuilder: bool
	#buildCount: int
	def __init__(self, name, mineral, gas, supply, time, builtBy, reqs, killsBuilder = False, supplied = 0, buildCount = 1):
		self.name = name
		self.mineral = mineral
		self.gas = gas
		self.supply = supply
		self.time = time
		self.builtBy = builtBy
		self.reqs = reqs
		self.killsBuilder = killsBuilder
		self.supplied = supplied
		self.buildCount = buildCount
		
	def canBuild(self, player):
		if player.minerals < self.mineral:
			return False
		if player.gas < self.gas:
			return False
		if player.freeSupply() < self.supply:
			return False
		if not(player.available[builtBy] > 0):
			return False
		for req in self.reqs:
			if not(player.reqs[req]):
				return False
		return True
		
	def build(self, player):
		player.minerals -= self.mineral
		player.gas -= self.gas
		player.usedSupply += self.supply
		
	def finish(self, player):
		player.reqs[self.name] = True
		player.available[self.name] += buildCount
		
	def kill(self, player):
		player.usedSupply -= self.supply
		player.available[self.name] -= 1
		
	@staticmethod
	def strToUnit(string):
		args = string.split(";")
		name = args[0]
		mineral = int(args[1])
		gas = int(args[2])
		supply = int(args[3])
		time = int(args[4])
		if(int(args[7])):
			killsBuilder = True
		else:
			killsBuilder = False
		supplied = args[8]
		buildCount = args[9]
		return Unit(name, mineral, gas, supply, time, None, None, killsBuilder, supplied, buildCount)
		
	@staticmethod
	def fixDepends(string, index):
		args = string.split(";")
		thisUnit = Unit.allUnits[index]
		reqs = []
		for unit in Unit.allUnits:
			if(unit.name == args[5]):
				builtBy = unit
			if(unit.name in (args[6].split(","))):
				reqs.append(unit)
		thisUnit.builtBy = builtBy
		thisUnit.reqs = reqs
		
	@staticmethod
	def importFile(fileName):
		f = open(fileName, "r")
		lines = (f.readlines())[1:]
		f.close()
		for line in lines:
			Unit.allUnits.append(Unit.strToUnit(line))
		for i, line in enumerate(lines):
			Unit.fixDepends(line, i)
			
Unit.importFile('units.csv')
for unit in Unit.allUnits:
    print unit.builtBy.name
